local duji=fk.CreateSkill{
    name = "kpaI__duji",
}

Fk:loadTranslationTable{
  
  ["kpaI__duji"] = "睹机",
  [":kpaI__duji"] = "出牌阶段限一次，你可令一名角色展示手牌并选择一项：1.将所有基本手牌当一张基本牌使用；"..
  "2.将所有非基本手牌当一张普通锦囊牌使用。然后若其不为你，你可执行另一项。",
  
  ["$kpaI__duji1"] = "良策者，胜败之机也。",
  ["$kpaI__duji2"] = "以帷幄之规，下攻拔之捷。",
  
  ["#kpaI__duji"] = "睹机：你可以令一名角色展示手牌并选择一项：1.将所有基本手牌当一张基本牌使用；<br>"..
  "2.将所有非基本手牌当一张普通锦囊牌使用。然后若其不为你，你可执行另一项。",
  ["#kpaI__duji-choice1"] = "将所有基本手牌当一张基本牌使用；或将所有非基本牌当一张普通锦囊牌使用",
  ["#kpaI__duji-choice2"] = "将所有基本手牌当一张基本牌使用",
  ["#kpaI__duji-choice3"] = "将所有非基本牌当一张普通锦囊牌使用",
}


duji:addEffect("active",{
  prompt = "#kpaI__duji",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(duji.name, Player.HistoryPhase) == 0
  end,
  target_filter = function(self,player, to_select, selected, selected_cards)
    return #selected < 1 and not to_select:isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local allCardNames = {}
    local text

    --- 将一种类型的所有牌当一种牌使用
    --- @param cardnames string[] @可转化的牌名
    --- @param p ServerPlayer @谁用牌
    --- @param bcards integer[] @被转化的牌
    --- @param nbcards integer[] @被转化的牌
    --- @param cancelable boolean @是否可以取消
    --- @param atext string @描述文本
    --- @trturn string? @ 返回卡牌使用框架。取消使用则返回空
    local usecardname = function(cardnames,p,bcards,nbcards,cancelable,atext)
      local use = room:askToUseVirtualCard(p,{
        name = cardnames,
        skill_name = duji.name,
        prompt = atext,
        cancelable = cancelable,
        extra_data = {bypass_times = true},
        skip = true,
      })
      if use then
        if use.card.type == Card.TypeBasic then
          use.card.subcards = bcards
          room:useCard(use)
          return "b"
        elseif use.card.type == Card.TypeTrick then
          use.card.subcards = nbcards
          room:useCard(use)
          return "t"
        end
      end
    end

    local handcards = target:getCardIds("h")
    target:showCards(handcards)
    local basic_cards = table.filter(handcards, function(cid)
      return Fk:getCardById(cid).type == Card.TypeBasic
    end)
    local non_basic_cards = table.filter(handcards, function(cid)
      return Fk:getCardById(cid).type ~= Card.TypeBasic
    end)
    if #basic_cards > 0 and #non_basic_cards > 0 then
      allCardNames = Fk:getAllCardNames("bt")
      text = "#kpaI__duji-choice1"
    elseif #basic_cards > 0 then
      allCardNames = Fk:getAllCardNames("b")
      text = "#kpaI__duji-choice2"
    elseif #non_basic_cards > 0 then
      allCardNames = Fk:getAllCardNames("t")
      text = "#kpaI__duji-choice3"
    end
    local useinfo = usecardname(allCardNames,target,basic_cards,non_basic_cards,false,text)

    if target == player or player.dead then return end

    handcards = player:getCardIds("h")
    player:showCards(handcards)
    basic_cards = table.filter(handcards, function(cid)
      return Fk:getCardById(cid).type == Card.TypeBasic
    end)
    non_basic_cards = table.filter(handcards, function(cid)
      return Fk:getCardById(cid).type ~= Card.TypeBasic
    end)
    if useinfo == "b" and #non_basic_cards > 0 then
      allCardNames = Fk:getAllCardNames("t")
      text = "#kpaI__duji-choice3"
    elseif useinfo == "t" and #basic_cards > 0 then
      allCardNames = Fk:getAllCardNames("b")
      text = "#kpaI__duji-choice2"
    end
    useinfo = usecardname(allCardNames,player,basic_cards,non_basic_cards,true,text)

  end,
})

return duji